package com.yq.homework.day23;

import java.util.Scanner;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/23 19:42
 * 分别自定义编译时异常和运行时异常，在方法中抛出异常，main方法中调用该方法，并处理相应的异常
 */
public class Demo02 {
    public static void main(String[] args) {
        try {
            func();
        } catch (B b) {
            b.printStackTrace();
        }


    }

    private static void func() throws B {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入分数");
        int i = scanner.nextInt();
        if (i<0 || i>100){
            // throw new A("分数不合法！");
            throw new B("分数不合法");
        }
    }

}


//运行时异常
class A extends RuntimeException {
    public  A(){}

    public A(String message) {

        super(message);
    }
}


class  B extends Exception{
    public B() {
    }

    public B(String message) {
        super(message);
    }
}